package com.multi.thread.chapter07.demo07;

import java.lang.Thread.UncaughtExceptionHandler;

public class ThreadException {
	
	private static class MyThread extends Thread {
		@Override
		public void run() {
			String username = null;
			System.out.println(username.hashCode());
		}
	}
	
	public static void main(String[] args) {
		MyThread t1 = new MyThread();
		t1.setName("线程t1");
		t1.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
			@Override
			public void uncaughtException(Thread t, Throwable e) {
				System.out.println("线程 " + t.getName() + " 出现了异常：");
				e.printStackTrace();
			}
		});
		t1.start();
		
		MyThread t2 = new MyThread();
		t2.setName("线程2");
		t2.start();
	}

}
